home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-08-24 | 1.4 KB | 33 lines | [TEXT/KAHL] |
- /******************************************************************************
- KeyIsDown by Daniel Gimpelevich
-
- Determine whether or not the specified key is being pressed. Keys
- are specified by hardware-specific key code (NOT the character).
-
- ******************************************************************************/
- Boolean KeyIsDown( short theKeyCode );
-
- Boolean KeyIsDown( short theKeyCode )
- {
- KeyMap theKeys;
-
- GetKeys(theKeys);
- /* Get state of each key */
-
- /* Ordering of bits in a KeyMap is truly bizarre. A KeyMap is a */
- /* 16-byte (128 bits) array where each bit specifies the start */
- /* of a key (0 = up, 1 = down). We isolate the bit for the */
- /* specified key code by first determining the byte position in */
- /* the KeyMap and then the bit position within that byte. */
- /* Key codes 0-7 are in the first byte (offset 0 from the */
- /* start), codes 8-15 are in the second, etc. The BitTst() trap */
- /* counts bits starting from the high-order bit of the byte. */
- /* For example, for key code 58 (the option key), we look at */
- /* the 8th byte (7 offset from the first byte) and the 5th bit */
- /* within that byte. */
-
- return( BitTst( ((char*) &theKeys) + theKeyCode / 8,
- (long) 7 - (theKeyCode % 8) ) );
- }
-
-